home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
redakcyjne
/
programy
/
FEBE (Firefox Environment Backup Extension) 5.0
/
febe-5.0-fx.xpi
/
chrome
/
febe.jar
/
content
/
febeUDBu.js
< prev
next >
Wrap
Text File
|
2007-06-10
|
17KB
|
451 lines
// author: Chuck Baker
// contact: firefox@customsoftwareconsult.com
// FEBE User-defined backup routines
var febeUDBuList = [];
var febeUDBuAction = new Number; // 1=New, 2=Edit, 3=Delete
var febeUDBuTrxPending = new Boolean(false);
function febeUDBuObj(Label, Type, Description, Path, Include){
this.Label = new String(Label);
this.Type = new Number(Type);
this.Description = new String(Description);
this.Path = new String(Path);
this.Include = new Boolean(Include);
return true;
}//febeUDBuObj
function febeLoadUDBu(){
var febeUDBuWin = window.openDialog("chrome://febe/content/febeUDBu.xul", febeMsg[147], "chrome,alwaysRaised,centerscreen,resizable");
return true;
}//febeLoadUDBu()
function febeNewUDBu(){
febeUDBuDisableAll();
document.getElementById("febeUDBuCaption").value = febeMsg[136];
febeUDBuAction = 1;
febeUDBuEnableNew();
return true;
}//febeNewUDBu()
function febeEditUDBu(){
febeUDBuDisableAll();
document.getElementById("febeUDBuCaption").value = febeMsg[137];
febeUDBuAction = 2;
febeUDBuPopulateListbox();
return true;
}//febeEditUDBu()
function febeDeleteUDBu(){
febeUDBuDisableAll();
document.getElementById("febeUDBuCaption").value = febeMsg[138];
febeUDBuAction = 3;
febeUDBuPopulateListbox();
return true;
}//febeDeleteUDBu()
function febeSelUDBu(){
var dd = document.getElementById("febeUDBuType");
if(dd.selectedIndex == -1){
var tmp = febeMsg[165];
febeAlert(tmp);
return false;
}//if
var type = dd.selectedIndex;
switch(type){
case 0: // File
febeSelUDBuFile();
break;
case 1: // Folder
febeSelUDBuFolder();
break;
}//switch
return true;
}//febeSelUDBu(){
function febeSelUDBuFile(){
// Select a file to backup
const nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
fp.init(window, febeMsg[133], nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterAll);
// Set the default directory to the current profile directory
febeProfDir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
fp.displayDirectory = febeProfDir;
var rv = fp.show();
if (rv == nsIFilePicker.returnOK){
rv = fp.file;
document.getElementById("febeUDBuSource").value = rv.path;
return true;
}//if
return false;
}//febeSelUDBuFile()
function febeSelUDBuFolder(){
// Select a folder to backup
const nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
fp.init(window, febeMsg[159], nsIFilePicker.modeGetFolder);
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
// Set the default directory to the current profile directory
febeProfDir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
fp.displayDirectory = febeProfDir;
var rv = fp.show();
if (rv == nsIFilePicker.returnOK){
rv = fp.file;
document.getElementById("febeUDBuSource").value = rv.path;
return true;
}//if
return false;
}//febeSelUDBuFolder()
function febeUDBuInit(){
febeSetMsgs();
// Get data from file - create template if needed
var febeDataFile = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
febeDataFile.append(FEBEDATAFILE);
if(!febeDataFile.exists()){
// Create the template
var dataFile = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
dataFile.init(febeDataFile, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
var charset = "UTF-8";
var os = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
.createInstance(Components.interfaces.nsIConverterOutputStream);
os.init(dataFile, charset, 4096, 0x0000);
os.writeString(febeMsg[182]+",0,"+febeMsg[181]+","+febeDataFile.path+",true\n");
os.close();
}//if
// Read the data
var dataFile = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
dataFile.initWithPath(febeDataFile.path);
// open an input stream from file
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
istream.init(dataFile, 0x01, 0444, 0);
istream.QueryInterface(Components.interfaces.nsILineInputStream);
var cis = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
.createInstance(Components.interfaces.nsIConverterInputStream);
var charset = "UTF-8";
cis.init(istream,charset, 1024, Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
var lis = cis.QueryInterface(Components.interfaces.nsIUnicharLineInputStream);
// read lines into array and parse into individual fields
febeUDBuList = [];
var line = {}, hasmore;
do {
hasmore = lis.readLine(line);
var febeUDBuItem = new febeUDBuObj;
var delimeter = ",";
var tmp = line.value;
var p = tmp.indexOf(delimeter);
febeUDBuItem.Label = tmp.slice(0,p);
tmp = tmp.slice(p+1);
p = tmp.indexOf(delimeter);
febeUDBuItem.Type = tmp.slice(0,p);
tmp = tmp.slice(p+1);
p = tmp.indexOf(delimeter);
febeUDBuItem.Description = tmp.slice(0,p);
tmp = tmp.slice(p+1);
p = tmp.indexOf(delimeter);
febeUDBuItem.Path = tmp.slice(0,p);
febeUDBuItem.Include = tmp.slice(p+1);
febeUDBuList[febeUDBuItem.Label] = febeUDBuItem;
} while(hasmore);
istream.close();
cis.close();
try {
document.documentElement.getButton("extra2").disabled = true;
}catch(e){;;}
return true;
}//febeUDBuInit()
function febeUDBuWrite(){
// Get data from file - create template if needed
var febeDataFile = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
febeDataFile.append("febeUserDefinedBuData.dat");
var dataFile = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
dataFile.init(febeDataFile, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
var charset = "UTF-8";
var os = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
.createInstance(Components.interfaces.nsIConverterOutputStream);
os.init(dataFile, charset, 4096, 0x0000);
for(var i in febeUDBuList){
var febeLabel = febeUDBuList[i].Label;
var febeType = febeUDBuList[i].Type;
var febeDesc = febeUDBuList[i].Description;
var febePath = febeUDBuList[i].Path;
var febeInclude = febeUDBuList[i].Include;
var dl = ",";
var dataString = febeLabel + dl + febeType + dl + febeDesc + dl + febePath+dl + febeInclude +"\n";
os.writeString(dataString);
}//for
os.close();
return true;
}//febeUDBuWrite()
function febeUDBuDisableAll(){
document.getElementById("febeUDBuCaption").value = febeMsg[134];
document.getElementById("febeUDBuList").removeAllItems();
document.getElementById("febeUDBuList").setAttribute("label",febeMsg[135]);
document.getElementById("febeUDBuList").disabled = true;
document.getElementById("febeUDBuLabelID").disabled = true;
document.getElementById("febeUDBuLabel").disabled = true;
document.getElementById("febeUDBuTypeID").disabled = true;
document.getElementById("febeUDBuType").disabled = true;
document.getElementById("febeUDBuDescID").disabled = true;
document.getElementById("febeUDBuDesc").disabled = true;
document.getElementById("febeUDBuSourceID").disabled = true;
document.getElementById("febeUDBuSource").disabled = true;
document.getElementById("febeUDBuBrowseBtn").disabled = true;
document.getElementById("febeIncludeInBu_id").disabled = true;
document.getElementById("febeUDBuSubmitBtn").disabled = true;
document.getElementById("febeUDBuLabel").value = "";
document.getElementById("febeUDBuDesc").value = "";
document.getElementById("febeUDBuSource").value = "";
document.getElementById("febeIncludeInBu_id").checked = false;
return true;
}//febeUDBuDisableAll()
function febeUDBuEnableNew(){
//document.getElementById("febeUDBuCaption").value = febeMsg[136];
document.getElementById("febeUDBuList").removeAllItems();
document.getElementById("febeUDBuList").setAttribute("label",febeMsg[135]);
document.getElementById("febeUDBuList").disabled = true;
document.getElementById("febeUDBuLabelID").disabled = false;
document.getElementById("febeUDBuLabel").disabled = false;
document.getElementById("febeUDBuTypeID").disabled = false;
document.getElementById("febeUDBuType").disabled = false;
document.getElementById("febeUDBuDescID").disabled = false;
document.getElementById("febeUDBuDesc").disabled = false;
document.getElementById("febeUDBuSourceID").disabled = false;
document.getElementById("febeUDBuSource").disabled = false;
document.getElementById("febeUDBuBrowseBtn").disabled = false;
document.getElementById("febeIncludeInBu_id").disabled = false;
document.getElementById("febeUDBuSubmitBtn").disabled = false;
document.getElementById("febeUDBuLabel").value = "";
document.getElementById("febeUDBuDesc").value = "";
document.getElementById("febeUDBuSource").value = "";
document.getElementById("febeIncludeInBu_id").checked = false;
return true;
}//febeUDBuEnableNew()
function febeUDBuEnableEdit(){
document.getElementById("febeUDBuList").removeAllItems();
document.getElementById("febeUDBuList").setAttribute("label",febeMsg[135]);
document.getElementById("febeUDBuList").disabled = false;
document.getElementById("febeUDBuLabelID").disabled = false;
document.getElementById("febeUDBuLabel").disabled = true;
document.getElementById("febeUDBuTypeID").disabled = false;
document.getElementById("febeUDBuType").disabled = false;
document.getElementById("febeUDBuDescID").disabled = false;
document.getElementById("febeUDBuDesc").disabled = false;
document.getElementById("febeUDBuSourceID").disabled = false;
document.getElementById("febeUDBuSource").disabled = false;
document.getElementById("febeUDBuBrowseBtn").disabled = false;
document.getElementById("febeIncludeInBu_id").disabled = false;
document.getElementById("febeUDBuSubmitBtn").disabled = false;
document.getElementById("febeUDBuLabel").value = "";
document.getElementById("febeUDBuDesc").value = "";
document.getElementById("febeUDBuSource").value = "";
document.getElementById("febeIncludeInBu_id").checked = false;
return true;
}//febeUDBuEnableEdit()
function febeUDBuEnableDelete(){
//document.getElementById("febeUDBuCaption").value = febeMsg[138];
document.getElementById("febeUDBuList").removeAllItems();
document.getElementById("febeUDBuList").setAttribute("label",febeMsg[135]);
document.getElementById("febeUDBuList").disabled = false;
document.getElementById("febeUDBuLabelID").disabled = false;
document.getElementById("febeUDBuLabel").disabled = true;
document.getElementById("febeUDBuTypeID").disabled = true;
document.getElementById("febeUDBuType").disabled = true;
document.getElementById("febeUDBuDescID").disabled = false;
document.getElementById("febeUDBuDesc").disabled = true;
document.getElementById("febeUDBuSourceID").disabled = false;
document.getElementById("febeUDBuSource").disabled = true;
document.getElementById("febeUDBuBrowseBtn").disabled = true;
document.getElementById("febeIncludeInBu_id").disabled = true;
document.getElementById("febeUDBuSubmitBtn").disabled = false;
document.getElementById("febeUDBuLabel").value = "";
document.getElementById("febeUDBuDesc").value = "";
document.getElementById("febeUDBuSource").value = "";
document.getElementById("febeIncludeInBu_id").checked = false;
return true;
}//febeUDBuEnableDelete()
function febeUDBuOK(){
febeUDBuWrite();
febeAlert(febeMsg[149]);
return true;
}//febeUDBuOK()
function febeUDBuCancel(){
if(febeUDBuTrxPending == true){
var style = "<style>color: red; font-weight: bold; font-size: 20px;</style>"
var tmp = style+febeMsg[139]+"\n";
tmp += style+febeMsg[140]+"\n\n";
tmp += febeMsg[141];
return febeConfirm(tmp);
}//if
return true;
}//febeUDBuCancel()
function febeUDBuSubmit(){
var febeUDBuItem = new febeUDBuObj;
febeUDBuItem.Label = document.getElementById("febeUDBuLabel").value;
febeUDBuItem.Type = document.getElementById("febeUDBuType").selectedIndex;
febeUDBuItem.Description = document.getElementById("febeUDBuDesc").value;
febeUDBuItem.Path = document.getElementById("febeUDBuSource").value;
febeUDBuItem.Include = document.getElementById("febeIncludeInBu_id").checked;
var key = febeUDBuItem.Label;
switch(febeUDBuAction){
case 1: // New
if(febeUDBuItem.Label == ""){
febeAlert(febeMsg[142]);
return false;
}//if
if(febeUDBuItem.Type == -1){
febeAlert(febeMsg[160]);
return false;
}//if
if(febeUDBuItem.Description == ""){
febeAlert(febeMsg[143]);
return false;
}//if
if(febeUDBuItem.Path == ""){
febeAlert(febeMsg[144]);
return false;
}//if
// See if label already exists
for(var tmp in febeUDBuList){
if(tmp == key){
febeAlert(febeMsg[145].replace("%key%",key));
return false;
}//if
}//for
febeUDBuList[key] = febeUDBuItem;
break;
case 2: // Edit
febeUDBuList[key] = febeUDBuItem;
break;
case 3: // Delete
delete febeUDBuList[key];
break;
default:// WTF??
;
}//switch
febeUDBuTrxPending = true;
document.documentElement.getButton("extra2").disabled = false;
febeUDBuDisableAll();
febeAlert(febeMsg[146]);
return true;
}//febeUDBuSubmit()
function febeUDBuPopulateListbox(){
// Clear existing items
var submenu = document.getElementById("febeUDBuList");
var children = submenu.childNodes;
var n = children.length;
for (var i = 0; i < n; i++) {
submenu.removeChild(children[0]);
}
for(var i in febeUDBuList){
document.getElementById("febeUDBuList").appendItem(febeUDBuList[i].Label,febeUDBuList[i].Label);
}//for
document.getElementById("febeUDBuList").disabled = false;
return true;
}//febeUDBuPopulateListbox()
function febeUDBuDisplayData(){
switch(febeUDBuAction){
case 2:
febeUDBuEnableEdit();
break;
case 3:
febeUDBuEnableDelete();
break;
}//switch
var key = document.getElementById("febeUDBuList").value;
document.getElementById("febeUDBuLabel").value = febeUDBuList[key].Label;
document.getElementById("febeUDBuType").selectedIndex = febeUDBuList[key].Type;
document.getElementById("febeUDBuDesc").value = febeUDBuList[key].Description;
document.getElementById("febeUDBuSource").value = febeUDBuList[key].Path;
document.getElementById("febeIncludeInBu_id").setAttribute("checked",febeUDBuList[key].Include);
return true;
}//febeUDBuDisplayData()
function febe_fillUDBUmenu(element){
// Populate the restore UDBU submenu
// Clear existing items
var submenu = document.getElementById(element);
var children = submenu.childNodes;
var n = children.length;
for (var i = 0; i < n; i++) {
submenu.removeChild(children[0]);
}
febeUDBuInit();
for(var i in febeUDBuList){
var oncommand = "febeRestoreUDBU('"+i+"');";
var aMenuItem=document.createElement("menuitem");
aMenuItem.setAttribute( "label" , febeUDBuList[i].Label);
aMenuItem.setAttribute( "oncommand" , oncommand);
aMenuItem.setAttribute( "tooltiptext" , febeMsg[170]+" "+febeUDBuList[i].Description);
document.getElementById(element).appendChild(aMenuItem);
}//for
return true;
}//febe_fillUDBUmenu()
function febeResetUDBu(){
var style = "<style>color: red; font-weight: bold; font-size: 14px;</style>"
var tmp = style+febeMsg[174]+"\n\n";
tmp += febeMsg[175];
if(!febeConfirm(tmp)){return true;};
var febeDataFile = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
febeDataFile.append(FEBEDATAFILE);
if(febeDataFile.exists()){febeDataFile.remove(false);}
febeUDBuList = [];
febeUDBuInit();
febeUDBuPopulateListbox();
febeUDBuDisableAll();
febeAlert(febeMsg[176]);
return true;
}//febeResetUDBu()
//febeAlert("febeDBM.js loaded");